package dao;

import java.util.Collection;

import models.Attempt;

import org.hibernate.Session;

import utils.HbnUtil;

public class AttemptDaoHbnImpl implements AttemptDao {

	@Override
	public void addAttempt(Attempt att) {
		Session session= HbnUtil.getSession();
		session.saveOrUpdate(att);
	}

	@Override
	public void delAttemptById(Long attId) {
		Session session= HbnUtil.getSession();
		Attempt att=selAttemptById(attId);
		session.delete(att);
	}

	@Override
	public Attempt selAttemptById(Long attId) {
		Session session= HbnUtil.getSession();
		String hql="from Attempt a where a.id=:attId";
		return (Attempt) session.createQuery(hql).setLong("attId", attId)
				.uniqueResult();
	}

	@Override
	public Collection<Attempt> selAttemptsByPaprId() {
		Session session= HbnUtil.getSession();
		String hql="from Attempt a join fetch a.examOfPapr eop";
		return session.createQuery(hql).list();
	}

	@Override
	public void updateAttempt(Attempt att) {
		addAttempt(att);
	}

}
